package com.spring.cloud.advice;


import com.spring.cloud.vo.ExceptionResult;
import com.spring.cloud.exception.GlobalException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @author hd
 * @date 2019/3/31
 *
 * 自定义异常处理
 */
@Slf4j
@ControllerAdvice   //拦截所有controller
public class BasicExceptionHandler {

    @ExceptionHandler(GlobalException.class)
    public ResponseEntity<ExceptionResult> handleException(GlobalException e) {
        return ResponseEntity.status(e.getExceptionEnum().value())
                .body(new ExceptionResult(e.getExceptionEnum()));
    }
}
